package com.lizardmind.haofudoctor.ui.diagnosis

import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import com.linxiao.framework.adapter.BaseAdapter
import com.linxiao.framework.adapter.DividerGridItemDecoration
import com.linxiao.framework.fragment.BaseFragment
import com.linxiao.framework.util.color
import com.linxiao.framework.util.getDataBinding
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.databinding.FragmentDiagnosisBinding
import com.lizardmind.haofudoctor.databinding.ItemDiagnosisBinding
import com.lizardmind.haofudoctor.manager.ImgManager
import com.lizardmind.haofudoctor.other.DiagnosisBean
import com.lizardmind.haofudoctor.other.rongYun.USER_PREFIX
import com.lizardmind.haofudoctor.test.TestActivity
import io.rong.imkit.RongIM
import io.rong.imlib.model.Conversation
import io.rong.imlib.model.UserInfo
import kotlinx.android.synthetic.main.fragment_diagnosis.*
import kotlinx.android.synthetic.main.include_title_text.*
import kotlinx.android.synthetic.main.include_title_text.view.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.support.v4.ctx
import org.jetbrains.anko.support.v4.startActivity

/**
 * 诊疗服务
 * Created by Extends on 2017/10/13 13:10
 */
class DiagnosisFragment : BaseFragment() {

    private val popView by lazy { LayoutInflater.from(context).inflate(R.layout.popview_diagnosis,null) }
    private lateinit var headView: View

    val binding by lazy { getDataBinding<FragmentDiagnosisBinding>(R.layout.fragment_diagnosis) }
    override fun onCreatRootView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        headView = LayoutInflater.from(context).inflate(R.layout.head_system_service,container,false)
        return binding.root
    }

    override fun onInitView(savedInstanceState: Bundle?) {
        titleDiagnosis.apply {
            imgRight.setImageResource(R.mipmap.jia)
            titleText.text = "诊疗服务"

            imgLeft.onClick {
//                startActivity(intentFor<EvaluationActivity>())
            }
            imgRight.onClick {
//                postApi<Request<DiagnoseDocumentsBean>>(
//                        hashMapOf("action" to "diagnose_info",
//                                "id" to "23",
//                                "token" to DoctorInfo.token),
//                        Consumer {
//                            it.dispose {
//                                if(it.documents_status==0){
//                                    //未填写，跳入填写界面
//                                    startActivity<FillDiagnoseOneActivity>("bean" to it)
////                                    startActivity<FillDiagnoseTwoActivity>("bean" to it)
//                                }else{
//                                    //已填写，跳入查看界面
//                                    startActivity<LookDiagnoseActivity>("bean" to it)
//                                }
//                            }
//                        }
//                )
//                startActivity<TestActivity>()
                imgRight.setImageResource(R.mipmap.jia2)
                showPopuWin()
            }


            tvContent.text = "防守打法撒的防守打法都十分大方地说"
            tvName.text = "官方助理"
            tvTime.text = "2017-12-12"
            imgIcon.setImageResource(R.mipmap.recommend_doctor)
        }
    }

        private fun showPopuWin() {
            val popWin = PopupWindow(popView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true)
            popWin.setBackgroundDrawable(ColorDrawable(0x00000000))
            popWin.showAsDropDown(imgRight, -270, 30)
            popWin.setOnDismissListener {
                imgRight.setImageResource(R.mipmap.jia)
            }
        }

}